package edu.sctu;

import com.mysql.cj.api.mysqla.result.Resultset;
import util.DBConnection;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * Created by LENOVO on 2018/6/24.
 */
public class AdminDao {

    DBConnection dbConnection = new DBConnection();

    /**
     * 管理员登录入口
     * @param connection
     * @param username
     * @param password
     * @return
     * @throws Exception
     */
    public Admin showAdmin(Connection connection,String username,String password) throws Exception {
        String sql = "select * from g_users where username='"+username+"' and password='"+password+"'";
        connection = dbConnection.getDBconnection();
        Statement statement = connection.createStatement();
        ResultSet resultset = statement.executeQuery(sql);
        Admin admin = new Admin();
        if(resultset.next()) {
            admin.setId(resultset.getInt("id"));
            admin.setUsername(resultset.getString("username"));
            admin.setPassword(resultset.getString("password"));
        }
        return admin;
    }
}
